// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.core.skinnedmodel.population;

import java.util.ArrayList;
import se.krka.kahlua.j2se.KahluaTableImpl;
import se.krka.kahlua.vm.KahluaTable;
import zombie.Lua.LuaManager;
import zombie.util.Type;

public final class DefaultClothing {
    public static final DefaultClothing instance = new DefaultClothing();
    public final DefaultClothing.Clothing Pants = new DefaultClothing.Clothing();
    public final DefaultClothing.Clothing TShirt = new DefaultClothing.Clothing();
    public final DefaultClothing.Clothing TShirtDecal = new DefaultClothing.Clothing();
    public final DefaultClothing.Clothing Vest = new DefaultClothing.Clothing();
    public boolean m_dirty = true;

    private void checkDirty() {
        if (this.m_dirty) {
            this.m_dirty = false;
            this.init();
        }
    }

    private void init() {
        this.Pants.clear();
        this.TShirt.clear();
        this.TShirtDecal.clear();
        this.Vest.clear();
        KahluaTable kahluaTable = Type.tryCastTo(LuaManager.env.rawget("DefaultClothing"), KahluaTable.class);
        if (kahluaTable != null) {
            this.initClothing(kahluaTable, this.Pants, "Pants");
            this.initClothing(kahluaTable, this.TShirt, "TShirt");
            this.initClothing(kahluaTable, this.TShirtDecal, "TShirtDecal");
            this.initClothing(kahluaTable, this.Vest, "Vest");
        }
    }

    private void initClothing(KahluaTable kahluaTable1, DefaultClothing.Clothing clothing, String string) {
        KahluaTable kahluaTable0 = Type.tryCastTo(kahluaTable1.rawget(string), KahluaTable.class);
        if (kahluaTable0 != null) {
            this.tableToArrayList(kahluaTable0, "hue", clothing.hue);
            this.tableToArrayList(kahluaTable0, "texture", clothing.texture);
            this.tableToArrayList(kahluaTable0, "tint", clothing.tint);
        }
    }

    private void tableToArrayList(KahluaTable kahluaTable, String string, ArrayList<String> arrayList) {
        KahluaTableImpl kahluaTableImpl = (KahluaTableImpl)kahluaTable.rawget(string);
        if (kahluaTableImpl != null) {
            int int0 = 1;

            for (int int1 = kahluaTableImpl.len(); int0 <= int1; int0++) {
                Object object = kahluaTableImpl.rawget(int0);
                if (object != null) {
                    arrayList.add(object.toString());
                }
            }
        }
    }

    public String pickPantsHue() {
        this.checkDirty();
        return OutfitRNG.pickRandom(this.Pants.hue);
    }

    public String pickPantsTexture() {
        this.checkDirty();
        return OutfitRNG.pickRandom(this.Pants.texture);
    }

    public String pickPantsTint() {
        this.checkDirty();
        return OutfitRNG.pickRandom(this.Pants.tint);
    }

    public String pickTShirtTexture() {
        this.checkDirty();
        return OutfitRNG.pickRandom(this.TShirt.texture);
    }

    public String pickTShirtTint() {
        this.checkDirty();
        return OutfitRNG.pickRandom(this.TShirt.tint);
    }

    public String pickTShirtDecalTexture() {
        this.checkDirty();
        return OutfitRNG.pickRandom(this.TShirtDecal.texture);
    }

    public String pickTShirtDecalTint() {
        this.checkDirty();
        return OutfitRNG.pickRandom(this.TShirtDecal.tint);
    }

    public String pickVestTexture() {
        this.checkDirty();
        return OutfitRNG.pickRandom(this.Vest.texture);
    }

    public String pickVestTint() {
        this.checkDirty();
        return OutfitRNG.pickRandom(this.Vest.tint);
    }

    private static final class Clothing {
        final ArrayList<String> hue = new ArrayList();
        final ArrayList<String> texture = new ArrayList();
        final ArrayList<String> tint = new ArrayList();

        void clear() {
            this.hue.clear();
            this.texture.clear();
            this.tint.clear();
        }
    }
}
